﻿using UnityEngine.UI;

public class DiamondNotEnoughPanel : AppUI
{
    public Text needDiamondText;


    public void Init(int needDiamond,int curDiamond)
    {
        needDiamondText.text = $"需要{needDiamond}钻石，当前拥有的钻石为{curDiamond}个";
    }

    public void OnClickShareGetDiamond()
    {
        GameDebug.Log($"DiamondNotEnoughPanel -> OnClickShareGetDiamond");
    }

    public void OnClickCharge()
    {
        GameDebug.Log($"DiamondNotEnoughPanel -> OnClickCharge");

        var goods = ConstData.Instance.GetGoods("diamond_03");

        MGame.instance.payCtrl.Pay(goods, OnPaymentValidFail, OnPaymentValidSuc);

        //充值埋点
        MGame.instance.dataTracking?.OnCharge("", goods, 1, "CNY", "Apple");
        ClientLog.Send(ClientLogId.Charge, $"goodId:{goods.goodsId}  name:{goods.name}");
    }

    void OnPaymentValidFail(string error)
    {
        GameDebug.LogError("OnPaymentValidFail:" + error);
        MGame.instance.ShowNoticePanel("支付失败，请重试");//购买成功!
    }
    void OnPaymentValidSuc(string goodsId, PaymentValidateResponseData response)
    {
        GoodsArche goodsArche = ConstData.Instance.GetGoods(goodsId);

        if (goodsArche != null && goodsArche.type == GoodsType.BuyDiamond)
        {
            MGame.instance.ShowNoticePanel($"购买成功！获得{goodsArche.value}钻石"/*Localization.instance.GetValue("successful_purchase")*/);//购买成功!

            //充值成功埋点
            MGame.instance.dataTracking?.OnChargeSuc("", goodsArche, 1);
            ClientLog.Send(ClientLogId.ChargeSuc, $"goodId:{goodsArche.goodsId}  name:{goodsArche.name}");

            GoBack();
        }
        else
        {
            GameDebug.LogError($"OnPaymentValidSuc,cannot find goods:{goodsId} ");
        }
    }
    public void GoBack()
    {
        //UIController.ShowUI<UserHomePanel>();

        UIController.ShowUI(UIController.prePanel.GetType());
    }
}